/**
 * Copyright 2007-2010 非也
 * All rights reserved. 
 * 
 * This library is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License v3 as published by the Free Software
 * Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, see http://www.gnu.org/licenses/lgpl.html.
 *
 */
package org.fireflow2.designer.eclipse.commands.group;

import java.util.UUID;

import org.fireflow.pdl.fpdl20.diagram.GroupShape;
import org.fireflow.pdl.fpdl20.diagram.basic.Label;
import org.fireflow.pdl.fpdl20.diagram.basic.impl.LabelImpl;
import org.fireflow.pdl.fpdl20.diagram.impl.GroupShapeImpl;
import org.fireflow.pdl.fpdl20.diagram.style.BoundsStyle;
import org.fireflow.pdl.fpdl20.process.SubProcess;
import org.fireflow2.designer.eclipse.commands.AbstractCreateNodeCommand;
import org.fireflow2.designer.eclipse.modelwrapper.NodeWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.SubProcessWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.GroupWrapper;

/**
 *
 * @author 非也 nychen2000@163.com
 * Fire Workflow 官方网站：www.firesoa.com 或者 www.fireflow.org
 *
 */
public class CreateGroupCommand extends AbstractCreateNodeCommand{

	/* (non-Javadoc)
	 * @see org.fireflow2.designer.eclipse.commands.AbstractCreateNodeCommand#createNodeWrapper()
	 */
	@Override
	protected NodeWrapper createNodeWrapper() {
		NodeWrapper tmpNodeWrapper = null;
		
		String poolID = UUID.randomUUID().toString();
		
		GroupShape poolShape = new GroupShapeImpl(poolID);
		org.fireflow.pdl.fpdl20.diagram.basic.Rectangle fireRect =
				(org.fireflow.pdl.fpdl20.diagram.basic.Rectangle )poolShape.getShape();
		

		
		fireRect.getBounds().getUpperLeftCorner().setX(rect.x);
		fireRect.getBounds().getUpperLeftCorner().setY(rect.y);
		fireRect.getBounds().setWidth(rect.width>200?rect.width:200);
		fireRect.getBounds().setHeight(rect.height>100?rect.height:100);
		
		if (fireRect.getTitle()==null){
			Label lb = new LabelImpl();
			fireRect.setTitleLabel(lb);
		}
		fireRect.getTitleLabel().setText(findANewNodeName(null,null));
		fireRect.getTitleLabel().getFont().setSize(10);
		fireRect.getTitleLabel().getFont().setColor("#FF0000");
		fireRect.setContentLabel(null);//group不需要content
		
		fireRect.getBounds().getBoundsStyle().setColor("#696969");
		
		fireRect.getBounds().getBoundsStyle().setLineType(BoundsStyle.LINETYPE_DASHED);
		fireRect.getBounds().getBoundsStyle().setThick(1);
		
		if (this.parentWrapper instanceof SubProcessWrapper){
			tmpNodeWrapper = new GroupWrapper((SubProcessWrapper)this.parentWrapper,poolShape);
		}else{
			tmpNodeWrapper = new GroupWrapper(((NodeWrapper)this.parentWrapper).getSubProcessWrapper(),poolShape);
		}
		
		
		return tmpNodeWrapper;
	}

	/* (non-Javadoc)
	 * @see org.fireflow2.designer.eclipse.commands.AbstractCreateNodeCommand#findANewNodeName(org.fireflow.pdl.fpdl20.process.Subflow, java.lang.String)
	 */
	@Override
	protected String findANewNodeName(SubProcess subflow, String nodeType) {
		return "";
	}

}
